package com.ruoyi.web.controller.project.patent;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.project.patent.PatentAuthorization;
import com.ruoyi.system.service.project.IPatentAuthorizationService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 专利授权Controller
 * 
 * @author ruoyi
 * @date 2025-08-12
 */
@RestController
@RequestMapping("/project/patentauthorization")
public class PatentAuthorizationController extends BaseController
{
    @Autowired
    private IPatentAuthorizationService patentAuthorizationService;

    /**
     * 查询专利授权列表
     */
    @GetMapping("/list")
    public TableDataInfo list(PatentAuthorization patentAuthorization)
    {
        startPage();
        List<PatentAuthorization> list = patentAuthorizationService.selectPatentAuthorizationList(patentAuthorization);
        return getDataTable(list);
    }

    /**
     * 导出专利授权列表
     */
    @Log(title = "专利授权", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PatentAuthorization patentAuthorization)
    {
        List<PatentAuthorization> list = patentAuthorizationService.selectPatentAuthorizationList(patentAuthorization);
        ExcelUtil<PatentAuthorization> util = new ExcelUtil<PatentAuthorization>(PatentAuthorization.class);
        util.exportExcel(response, list, "专利授权数据");
    }

    /**
     * 获取专利授权详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(patentAuthorizationService.selectPatentAuthorizationById(id));
    }

    /**
     * 新增专利授权
     */
    @Log(title = "专利授权", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PatentAuthorization patentAuthorization)
    {
        return toAjax(patentAuthorizationService.insertPatentAuthorization(patentAuthorization));
    }

    /**
     * 修改专利授权
     */
    @Log(title = "专利授权", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PatentAuthorization patentAuthorization)
    {
        return toAjax(patentAuthorizationService.updatePatentAuthorization(patentAuthorization));
    }

    /**
     * 删除专利授权
     */
    @Log(title = "专利授权", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(patentAuthorizationService.deletePatentAuthorizationByIds(ids));
    }
}
